<template>
  <div class="table-box">
    <!--    查询组件    -->
    <tw-form
      v-if="!mainData.hideForm"
      :lists="mainData.lists"
      :formData="mainData.formData"
      :labelWidth="mainData.labelWidth"
      :isFormBnts="mainData.isFormBnts"
      :extraField="mainData.extraField"
      @submitForm="seekTable"
      :foldNumber="mainData.foldNumber || 4"
      @onFormflag="onFormflag"
    ></tw-form>
    <!--    表格组件    -->
    <tw-virtualized-table
      ref="mainTable"
      :requiredParams="mainData.requiredParams"
      :id="mainData.id"
      :url="mainData.tableUrl"
      :totalUrl="mainData.totalUrl"
      :isLoadStatus="mainData.isLoadStatus"
      :method="mainData.method"
      :tableParams="mainData.formData"
      :isCheck="mainData.isCheck"
      :isExpand="mainData.isExpand"
      :selectable="mainData.selectable"
      :showIndex="mainData.showIndex"
      :showPagination="mainData.showPagination"
      :border="mainData.border"
      :botHeight="mainData.botHeight || 50"
      :tableIndex="mainData.tableIndex"
      :size="mainData.size"
      :columns="mainData.columns"
      :tableData="mainData.tableData"
      :tableBtns="mainData.tableBtns"
      :headBtns="mainData.headBtns"
      :tabindex="mainData.tabIndex || 0"
      :secusessCallback="mainData.secusessCallback"
      @tableCallback="tableCallback"
      @checkSelect="checkSelect"
      @rowExpand="rowExpand"
    >
      <template #tableHeader="scope">
        <slot name="tableHeader"></slot>
      </template>
      <template #table-l="scope">
        <slot name="table-l"></slot>
      </template>
      <template #table-c="scope">
        <slot name="table-c"></slot>
      </template>
      <template #table-r="scope">
        <slot name="table-r"></slot>
      </template>
    </tw-virtualized-table>
  </div>
</template>

<script setup lang="tsx" name="ContentMainVirtualized">
const { mainData } = defineProps({
  mainData: Object,
})

defineOptions({
    name: 'ContentMainVirtualized'
})
let mainTable = $ref(null)

const onFormflag = () => {
  setTimeout(() => {
    mainTable.setTableDataHeight()
  }, 100)
}
let emits = defineEmits(['tableCallback', 'submitForm', 'checkSelect', 'rowExpand'])

const tableCallback = (data) => {
  emits('tableCallback', data)
}

const checkSelect = (data) => {
  emits('checkSelect', data)
}

const rowExpand = (data) => {
    emits('rowExpand', data)
}

const getTable = () => {
    mainData.formData.pageNumber = 1
    mainTable.getTable()
}

const getTotal= () => {
    mainTable.getTotal()
}

const seekTable = () => {
    mainData.formData.pageNumber = 1
    if(mainData.tableUrl){
        getTable()
        mainTable.setShwoTotalStatus()
        mainTable.setLoadStatus()
    }
    emits('submitForm', mainData.formData)
}

const getAllCheck = () => {
  return mainTable.getAllCheck()
}

const getTableLists = () => {
  return mainTable.dataList
}

const setTableLists = (lists) => {
  mainTable.setTableLists(lists)
}

const setTableTotal = (num) => {
    mainTable.setTableTotal(num)
}

defineExpose({ getTable, getAllCheck, getTableLists, setTableLists, setTableTotal })
</script>



<style scoped lang="scss"></style>
